/**
 * @autor xue
 * @descrption 我的报告
 */

import HttpService from '../../../services/HttpService'
import ApiUrl from '../../../services/ApiUrl'
import Util from '../../../services/Util'
var app = getApp();
app.getUserInfo();
Page({
  data: {
      userInfo: wx.getStorageSync('profile') || {}
  },
  getReportlist: function () {
    let self = this;
    let opts = {
      apiObj: ApiUrl.panelReportList,
      path:{
        member_id:wx.getStorageSync('profile').member.id
      }
    }
    HttpService.accessAPI(opts).then(function (result) {

      console.log('get report list success', result);
      let statusArr = {
        'completed': '已完成',
        'no_process': '采样中',
        'processed': '检测中',
        'ignored': '样本不合格'
      };
        let statusArrColor = {
            'completed': '#999999',
            'no_process': '#EE9E1A',
            'processed': '#EE9E1A',
            'ignored': '#FB4737'
        }
      for (let i = 0; i < result.data.length; i++) {
        if (result.data[i].rpt_expired_at){
          result.data[i].rpt_expired_at = Util.unixToEndTime(result.data[i].rpt_expired_at);
        }

        if (result.data[i].updated_at){
            result.data[i].updated_at = Util.unixToDate(result.data[i].updated_at);
        }

        if (result.data[i].progress){
            result.data[i].progressColor = statusArrColor[result.data[i].progress];
            result.data[i].progress = statusArr[result.data[i].progress];
        }
      }
      self.setData({
        reportList: result.data
      })
    });
  },
  onLoad: function (option) {
      let self = this;
      self.userInfo= wx.getStorageSync('profile');
      self.getReportlist();
  }
})